<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ider管理</title>
    <script type="text/javascript" src="../common/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../common/dateFormat.js"></script>
    <script type="text/javascript" src="../common/commonQuery.js"></script>
    <script type="text/javascript" src="../common/commonManager.js"></script>
    <link rel="stylesheet" href="../common/common.css" type="text/css">
    <script type="text/javascript">

        function createTableHead() {
            var tr = "<tr>";
            tr += "<th align='left' width='20%'>id编码</th>"
            tr += "<th align='left' width='7%'>周期类型</th>"
            tr += "<th align='left' width='18%'>id最大值（不包含）</th>"
            tr += "<th align='left' width='10%'>单次获取id的最大数量（包含）</th>"
            tr += "<th align='left' width='5%'>因数</th>"
            tr += "<th align='left' width='40%'>生产者</th>"
            tr += "</tr>"

            return tr;
        }

        function creteTableRow(info) {
            var tr = "<tr>";
            tr += "<td>" + info.idCode + "</td>";
            tr += "<td>" + toPeriodTypeStr(info.periodType) + "</td>";
            tr += "<td>" + toMaxIdStr(info.maxId) + "</td>";
            tr += "<td>" + toMaxAmount(info.maxAmount) + "</td>";
            tr += "<td>" + info.factor + "</td>";
            tr += "<td>" + producerColumn(info.producerInfos) + "</td>";
            tr += "</tr>"

            return tr;
        }

        function producerColumn(producerInfos) {
            var table = "<table width='100%'>";
            table += "<tr>";
            table += "<th align='left' width='10%'>序号</th>";
            table += "<th align='left' width='52%'>当前周期</th>";
            table += "<th align='left' width='48%'>当前id</th>";
            table += "</tr>";
            for (var i = 0; i < producerInfos.length; i++) {
                table += "<tr>";
                table += "<td>" + producerInfos[i].index + "</td>";
                table += "<td>" + toDateStr(producerInfos[i].currentPeriod) + "</td>";
                table += "<td>" + producerInfos[i].currentId + "</td>";
                table += "</tr>";
            }
            table += "</table>";
            return table;
        }

        function toPeriodTypeStr(periodType) {
            if (periodType == 'HOUR') {
                return "每小时";
            }
            if (periodType == "DAY") {
                return "每天";
            }
            if (periodType == "MONTH") {
                return "每月";
            }
            if (periodType == "YEAR") {
                return "每年";
            }
            if (periodType == "NONE") {
                return "无";
            }
            alert("无法识别的周期类型：" + periodType);
        }

        function toMaxIdStr(maxId) {
            if (maxId == null) {
                return "不限制";
            }
            return maxId;
        }

        function toMaxAmount(maxAmount) {
            if (maxAmount == null) {
                return "不限制";
            }
            return maxAmount;
        }

        function toDateStr(time) {
            if (time == null) {
                return "无";
            }
            return new Date(time).format("yyyy-MM-dd hh:mm:ss.S");
        }

        $(document).ready(function () {
            if (manager.type == 'ADMIN') {
                $('#adminDiv').show();
            } else {
                $('#adminDiv').hide();
            }
        })
    </script>
</head>
<body>
<br/>
<div>
    <form id="queryForm" action="../manage/ider/queryManagedIders">
        id编码：<input type="text" name="idCode">
        <input type="button" onclick="pageNo = 1;query();" value="查询">
    </form>
</div>
<div id="tableDiv" class="table-solid"></div>
<div id="pageFoot">
    <button onclick="previousPage()">上一页</button>
    <span id="currentPageNo">1</span>
    <button onclick="nextPage()">下一页</button>
    总页数：<span id="totalPage"></span>
</div>
<br/>
<div>
    <table width="100%">
        <tr>
            <td valign="top">
                修改id提供者最大数据：
                <form id="modifyMaxForm" action="../manage/ider/modifyMax">
                    <table>
                        <tr>
                            <td align="right">id编码：</td>
                            <td><input type="text" name="idCode"></td>
                        </tr>
                        <tr>
                            <td align="right">新的id最大值<br/>(不填表示不限制)：</td>
                            <td><input type="text" name="newMaxId"></td>
                        </tr>
                        <tr>
                            <td align="right">新的单次获取id最大数量<br/>(不填表示不限制)：</td>
                            <td><input type="text" name="newMaxAmount"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer('modifyMaxForm')" value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </td>
            <td valign="top">
                修改id提供者的因数：
                <form id="modifyFactorForm" action="../manage/ider/modifyFactor">
                    <table>
                        <tr>
                            <td align="right">id编码：</td>
                            <td><input type="text" name="idCode"></td>
                        </tr>
                        <tr>
                            <td align="right">新的因数：</td>
                            <td><input type="text" name="newFactor"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer('modifyFactorForm')"
                                                     value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </td>
            <td valign="top">
                修改id提供者当前数据（<font color="red">危险</font>）：
                <form id="modifyCurrentForm" action="../manage/ider/modifyCurrent">
                    <table>
                        <tr>
                            <td align="right">id编码：</td>
                            <td><input type="text" name="idCode"></td>
                        </tr>
                        <tr>
                            <td align="right">新的当前周期(无周期则不填)<br/>(格式yyyyMMddHH):</td>
                            <td><input type="text" name="newCurrentPeriod"></td>
                        </tr>
                        <tr>
                            <td align="right">新的当前id：</td>
                            <td><input type="text" name="newCurrentId"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer('modifyCurrentForm')"
                                                     value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
    </table>
</div>
<div id="adminDiv" style="display:none;">
    <table width="70%">
        <tr>
            <td valign="top">
                新增id提供者：
                <form id="addForm" action="../manage/ider/add">
                    <table>
                        <tr>
                            <td align="right">id编码：</td>
                            <td><input type="text" name="idCode"></td>
                        </tr>
                        <tr>
                            <td align="right">周期类型：</td>
                            <td>
                                <select name="periodType">
                                    <option value="HOUR">每小时</option>
                                    <option value="DAY">每天</option>
                                    <option value="MONTH">每月</option>
                                    <option value="YEAR">每年</option>
                                    <option value="NONE">无</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">id最大值<br/>（不填表示不限制）：</td>
                            <td><input type="text" name="maxId"></td>
                        </tr>
                        <tr>
                            <td align="right">单次获取id最多数量<br/>（不填表示不限制）：</td>
                            <td><input type="text" name="maxAmount"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer('addForm')" value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </td>
            <td valign="top">
                删除id提供者（<font color="red">危险</font>）：
                <form id="deleteForm" action="../manage/ider/delete">
                    <table>
                        <tr>
                            <td align="right">id编码：</td>
                            <td><input type="text" name="idCode"></td>
                        </tr>
                        <tr>
                            <td align="right"><input type="button" onclick="requestServer('deleteForm')" value="提交">
                            </td>
                            <td></td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
    </table>
</div>
<br/>
</body>
</html>